/**
 * 生成裁剪视频命令
 */

const path = require("path");
const ffmpegPath = path.join(__dirname , '../', 'ffmpeg', 'ffmpeg.exe');


function clip_video(filepath, savePath, start_time, duration) {

    start_time = computerTime(start_time);

    duration = computerTime(duration);

    let cmdStr = `"${ffmpegPath}" -y -ss ${start_time} -t ${duration} -i "${filepath}" -c:v libx264 -preset superfast -c:a copy "${savePath}"`;

    return cmdStr;
}

// 秒转时分秒
function computerTime(second) {
    let hours = Math.floor((second % 86400) / 3600);
    let minutes = Math.floor(((second % 86400) % 3600) / 60);
    let seconds = Math.floor(((second % 86400) % 3600) % 60);

    if (hours < 10) hours = `0${hours}`;
    if (minutes < 10) minutes = `0${minutes}`;
    if (seconds < 10) seconds = `0${seconds}`;

    return `${hours}:${minutes}:${seconds}`;
}

module.exports = clip_video;